558B - Amr and The Large Array - CodeForces Solution


implementation *1300

Please click on ads to support us..

Python Code:

n = int(input())
l, r = 1, n
a = list(map(int, input().split()))
dd = dict()
for idx, i in enumerate(a):
    try:
        dd[i] = (dd[i][0]+1, dd[i][1], idx+1, max(dd[i][3], idx+1 - dd[i][1]))
    except:
        dd[i] = (1, idx+1, idx+1, 0)

d = n
mx = max(dd.values())[0]
temp = [i for i in dd.values() if i[0] == mx]
m_d = sorted(temp, key=lambda x: x[3])
temp_1 = [i for i in temp if i[3] == m_d[0][3]]
_, l, r, _ = temp_1[0]
print(l, r)

C++ Code:

#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
void solve();
#pragma GCC optimize("Ofast","inline","-ffast-math")
const int N = 101000;
int n, mx, d[N], dk[N * 10], firs[N * 10], last[N * 10];
int main(){
    // int t = 1; cin >> t;
    // while(t-- > 0) solve();
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> d[i];
        dk[d[i]]++;
        mx = max(mx, dk[d[i]]);
        if(!firs[d[i]]) firs[d[i]] = i;
        last[d[i]] = i;
    } int res = N, cur1, cur2;
    for(int i = 1; i < N * 10; i++){
        if(dk[i] == mx)
            if(res > last[i] - firs[i] + 1){
                res = last[i] - firs[i] + 1;
                cur1 = firs[i]; cur2 = last[i];
            }
    } cout << cur1 << " " << cur2;
}
const int fastIO = [](){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    return 0;
}();


Comments

Submit
0 Comments
More Questions

450A - Jzzhu and Children
546A - Soldier and Bananas
32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks
292B - Network Topology
1339A - Filling Diamonds
910A - The Way to Home
617A - Elephant
48A - Rock-paper-scissors
294A - Shaass and Oskols
1213A - Chips Moving
490A - Team Olympiad
233A - Perfect Permutation
1360A - Minimal Square
467A - George and Accommodation
893C - Rumor
227B - Effective Approach
1534B - Histogram Ugliness
1611B - Team Composition Programmers and Mathematicians
110A - Nearly Lucky Number
1220B - Multiplication Table
1644A - Doors and Keys
1644B - Anti-Fibonacci Permutation
1610A - Anti Light's Cell Guessing
349B - Color the Fence
144A - Arrival of the General